Skip to content

feat(cli,db): add minute/hour/week/month granularities and --weeks/--months windows - #8

Open
lorecanc wants to merge 1 commit into
rchardx:mainfrom
lorecanc:feat/time-granularities
Open

feat(cli,db): add minute/hour/week/month granularities and --weeks/--months windows#8
lorecanc wants to merge 1 commit into
rchardx:mainfrom
lorecanc:feat/time-granularities

Conversation

@lorecanc

@lorecanc lorecanc commented Aug 5, 2026

Copy link
Copy Markdown

Summary

Extends the daily breakdown into a full set of time buckets and adds week/month time windows:

  • --by minute|hour|week|month (in addition to day) via a new OpenCodeDB.by_time() query (SQLite strftime with localtime; labels like 2026-08-05 16:00, 2026-W31, 2026-08). daily() is kept as a compatibility alias.
  • --weeks N / --months N on both run and insights (month = 30 days, matching the m unit of --since). Precedence: --since > --days > --weeks/--months.

Cross-PR note

by_time() accepts a reserved filters parameter that forwards to the query layer once row filters land (PR feat/filters-and-output); it is inert here. The Filters dataclass in this PR is identical to the one in that PR, so git deduplicates it at merge time.

Changes

  • src/opencode_usage/db.py: _TIME_FORMATS, by_time(), Filters (plumbing)
  • src/opencode_usage/cli.py: --weeks/--months, extended --by choices, _resolve_since precedence
  • src/opencode_usage/render.py: render_time() with per-granularity labels; render_daily() kept as an alias
  • tests/test_db.py, tests/test_cli.py: new tests (bucket label formats, fallback, flag parsing, precedence)
  • README.md: documented

Verification

  • uv run pytest tests/ — 384 passed
  • uvx ruff check . and uvx ruff format --check . — clean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants